home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 1256 / cppredoc.c_ / cppredoc.c
C/C++ Source or Header  |  1997-04-18  |  10KB  |  266 lines

  1. /* EasyCODE(C++) V5.1 02.03.1995 18:29:03 */
  2. /* EasyCODE O
  3. If=vertical
  4. LevelNumbers=no
  5. LineNumbers=no
  6. ScreenFont=Courier New,,80,9220,-11,0,400,0,0,0,0,0,0,3,2,1,49
  7. PrinterFont=Courier New,,80,17414,-34,0,400,0,0,0,0,0,0,3,2,1,49
  8. LastLevelId=9 */
  9.  
  10. /* EasyCODE ( 1
  11.    cppredoc.c */
  12.  
  13. /* EasyCODE ( 9
  14.    Includes, Defines, Globals */
  15. #include "conv.h"                          // include header files
  16. #include "tabledef.h"
  17. #include <stdio.h>
  18. #include "c_filt.h"
  19.  
  20. #define ERR_KEYWORD     "Illegal keyword"  // define error messages
  21. #define ERR_EOF         "Unexpected EOF"
  22. #define ERR_NO_KEYWORD  "No keyword in line"
  23. #define ERR_COMMENT1    "Comment not closed"
  24. #define ERR_COMMENT2    "Unexpected end of comment" 
  25.  
  26. #define USAGEMSG        "Usage: %s inputfile outputfile\n"
  27.  
  28. FILE *infile, *outfile;                    // variables declaration
  29. BOOL bEnd, bInBlockOrLevelOrFunction;
  30. char delimiter[2];
  31. int key_num, line_nr, Nullvalue;
  32. /* EasyCODE ) */
  33.  
  34. /* EasyCODE ( 7
  35.    convert */
  36.  
  37. /* EasyCODE F */
  38. void convert(int key_nr) 
  39. /**************************************************************************************
  40.  **           Function     : convert
  41.  **           Parameters   : Key_nr of keyword
  42.  **           Return value : none
  43.  **  Purpose: Create new ETF file, containing only comments and constructs but no 
  44.  **           statements. Conversion is done line by line using the function 
  45.  **           CommentFilter to get the comments.
  46. **************************************************************************************/
  47.    {
  48.    switch (key_nr 
  49.            /* Processing depends on keyword */)
  50.       {
  51.       case ETF_EASYCODE /* Keyword: EasyCode */:
  52.       case ETF_SHORTINFO /* Keyword: ShortInfo */:
  53.       case ETF_ENDSHORTINFO /* Keyword: EndShortInfo */:
  54.       case ETF_OPTIONS /* Keyword: Options */:
  55.       case ETF_IFLAYOUT /* Keyword: IfLayout */:
  56.       case ETF_LEVELNUMBERS /* Keyword: LevelNumbers */:
  57.       case ETF_LINENUMBERS /* Keyword: LineNumbers */:
  58.       case ETF_CONSTRUCTNUMBERS /* Keyword: ConstructNumbers */:
  59.       case ETF_SCREENFONT /* Keyword: ScreenFont */:
  60.       case ETF_PRINTERFONT /* Keyword: PrinterFont */:
  61.       case ETF_LASTLEVELID /* Keyword: LastLevelId */:
  62.       case ETF_ENDOPTIONS /* Keyword: EndOptions */:
  63.       case ETF_IF /* Keyword: if */:
  64.       case ETF_THEN /* Keyword: Then */:
  65.       case ETF_ELSE /* Keyword: Else */:
  66.       case ETF_ENDIF /* Keyword: EndIf */:
  67.       case ETF_WHILE /* Keyword: While */:
  68.       case ETF_WHILEBODY /* Keyword: WhileBody */:
  69.       case ETF_ENDWHILE /* Keyword: EndWhile */:
  70.       case ETF_BLOCKBODY /* Keyword: BlockBody */:
  71.       case ETF_ENDBLOCK /* Keyword: EndBlock */:
  72.       case ETF_LEVELBODY /* Keyword: LevelBody */:
  73.       case ETF_ENDLEVEL /* Keyword: EndLevel */:
  74.       case ETF_FOR /* Keyword: For */:
  75.       case ETF_FORBODY /* Keyword: ForBody */:
  76.       case ETF_ENDFOR /* Keyword: EndFor */:
  77.       case ETF_DOWHILE /* Keyword: DoWhile */:
  78.       case ETF_UNTIL /* Keyword: Until */:
  79.       case ETF_ENDDOWHILE /* Keyword: EndDoWhile */:
  80.       case ETF_BREAK /* Keyword: Break */:
  81.       case ETF_CONTINUE /* Keyword: Continue */:
  82.       case ETF_CSWITCH /* Keyword: CSwitch */:
  83.       case ETF_CSWITCHBODY /* Keyword: CSwitchBody */:
  84.       case ETF_ENDCSWITCH /* Keyword: EndCSwitch */:
  85.       case ETF_CCASEBRANCH /* Keyword: CCaseBranch */:
  86.       case ETF_CCASEBRANCHBODY /* Keyword: CCaseBranchBody */:
  87.       case ETF_ENDCCASEBRANCH /* Keyword: EndCCaseBranch */:
  88.       case ETF_DEFAULT /* Keyword: Default */:
  89.       case ETF_ENDDEFAULT /* Keyword: EndDefault */:
  90.       case ETF_RETURN /* Keyword: Return */:
  91.       case ETF_ENDRETURN /* Keyword: EndReturn */:
  92.       case ETF_CLASSBODY /* Keyword: ClassBody */:
  93.       case ETF_ENDCLASSBODY /* Keyword: EndClassBody */:
  94.       case ETF_ENDCLASS /* Keyword: EndClass */:
  95.       case ETF_PRIVATE /* Keyword: Private */:
  96.       case ETF_PUBLIC /* Keyword: Public */:
  97.       case ETF_PROTECTED /* Keyword: Protected */:
  98.       case ETF_FUNCTIONBODY /* Keyword: FunctionBody */:
  99.       case ETF_ENDFUNCTION /* Keyword: EndFunction */:
  100.          StoreLine( inbuf, outfile);
  101.          /* All lines before are written unmodified to the output file */
  102.          break;
  103.       case ETF_CLASS /* Keyword: Class */:
  104.       case ETF_FUNCTION /* Keyword: Function */:
  105.       case ETF_LEVEL /* Keyword: Level */:
  106.       case ETF_BLOCK /* Keyword: Block */:
  107.          StoreLine( inbuf, outfile);
  108.          bInBlockOrLevelOrFunction = TRUE;
  109.          /* Store keyword and set flag bInBlockOrLevelOrFunction because
  110.             following text shall not be filtered. */
  111.          break;
  112.       case ETF_LINE /* Keyword: Line */:
  113.          if (bInBlockOrLevelOrFunction
  114.              /* If within block header or level header */)
  115.             {
  116.             StoreLine( inbuf, outfile); 
  117.             /* Store line unmodified */
  118.             }
  119.          else
  120.             {
  121.             /* Line has to be filtered */
  122.             switch (CommentFilter( &Nullvalue, outfile)
  123.                     /* Call function for filtering comments */)
  124.                {
  125.                case ERROR_COMMENT
  126.                     /* Error filtering comments */:
  127.                   err_msg( line_nr, ERR_COMMENT2);
  128.                   /* Print error message */
  129.                   break;
  130.                case ERROR_EOF
  131.                     /* Unexpected EOF */:
  132.                   err_msg( line_nr, ERR_EOF);
  133.                   break;
  134.                default:
  135.                   break;
  136.                }
  137.             }
  138.          break;
  139.       case ETF_TEXT /* Keyword: Text */:
  140.          StoreLine( inbuf, outfile);
  141.          /* Save keyword */
  142.          break;
  143.       case ETF_ENDTEXT /* Keyword: EndText */:
  144.          if (bInBlockOrLevelOrFunction
  145.              /* If within block header or level header */)
  146.             {
  147.             bInBlockOrLevelOrFunction = FALSE;
  148.             /* At end of block header or level header flag has to be reset */
  149.             }
  150.          if ((bInBlockComment) || (bInLineComment)
  151.              /* If within block header or level header */)
  152.             {
  153.             err_msg(line_nr, ERR_COMMENT1);
  154.             /* Error message because comment is not finished */
  155.             }
  156.          StoreLine( inbuf, outfile);
  157.          /* Save keyword */
  158.          break;
  159.       case ETF_DUMMY /* Keyword: Dummy */:
  160.          if (bInBlockOrLevelOrFunction
  161.              /* Dummy in block header or level header */)
  162.             {
  163.             bInBlockOrLevelOrFunction = FALSE;
  164.             /* Reset flag for comment filtering */
  165.             }
  166.          StoreLine( inbuf, outfile);
  167.          /* Save Dummy keyword */
  168.          break;
  169.       case NO_KEYWORD /* Keyword: NO_KEYWORD */:
  170.          err_msg( line_nr, ERR_NO_KEYWORD);
  171.          exit(1);
  172.          /* Error message and program termination if line without keyword */
  173.          break;
  174.       case ERROR_KEYWORD /* Keyword: ERROR_KEYWORD */:
  175.          err_msg( line_nr, ERR_KEYWORD);
  176.          exit(1);
  177.          /* Error message and program termination if invalid keyword */
  178.          
  179.  
  180.          break;
  181.       case EOF_KEYWORD /* Keyword: EOF_KEYWORD */:
  182.          err_msg( line_nr, ERR_EOF);
  183.          exit(1);
  184.          /* Error message and program termination if unexpected EOF */
  185.          break;
  186.       default:
  187.          err_msg(line_nr, ERR_KEYWORD);
  188.          exit(1);
  189.          /* Error message and program termination if unknown keyword */
  190.          break;
  191.       }
  192.    }
  193. /* EasyCODE ) */
  194.  
  195. /* EasyCODE ( 8
  196.    main */
  197.  
  198. /* EasyCODE F */
  199. /*****************************************************************************************
  200. **           Function:   main
  201. **           Parameters: Inputfile und Outputfile
  202. *****************************************************************************************/
  203. main(argc,argv)
  204. int argc;
  205. char *argv[];
  206.    {
  207.    int Nullvalue = 0;
  208.    int level_nr = 0;                  // Counter for open levels
  209.    bInBlockOrLevelOrFunction = FALSE; // Flag indicating position within block header or level header
  210.    if (argc != 3
  211.        /* Number of arguments not 3 */)
  212.       {
  213.       fprintf(stderr, USAGEMSG, argv[0]);
  214.       exit(1);
  215.       /* error message */
  216.       }
  217.    if (strcmp(argv[1], argv[2]) == 0
  218.        /* Same input file and output file */)
  219.       {
  220.       fprintf(stderr, USAGEMSG, argv[0]);
  221.       exit(1);
  222.       /* error message */
  223.       }
  224.    line_nr = 0;                 // Initialize line number
  225.    /* EasyCODE - */
  226.    infile = OpenInput(argv[1]);      // Open input file
  227.    outfile = OpenOutput(argv[2]);    // Open output file
  228.    while (!(bEnd = ReadLine(inbuf, infile))
  229.           /* not EOF */)
  230.       {
  231.       ++line_nr;     // Count lines
  232.       /* EasyCODE - */
  233.       convert( key_num = GetKeyword( delimiter, i_buf));
  234.       /* Call conversion function */
  235.       switch (key_num
  236.               /* Last keyword */)
  237.          {
  238.          case ETF_LEVEL /* Keyword: Level */:
  239.             level_nr++;      // Increment level counter
  240.             break;
  241.          case ETF_ENDLEVEL /* Keyword: EndLevel */:
  242.             level_nr--;     // Decrement level counter
  243.             break;
  244.          }
  245.       }
  246.    if (key_num != ETF_ENDLEVEL
  247.        /* EOF but last keyword not ENDLEVEL */)
  248.       {
  249.       err_msg( line_nr, ERR_EOF );
  250.       /* error message */
  251.       }
  252.    else
  253.       {
  254.       if (level_nr != 0
  255.           /* Level depth not 0 */)
  256.          {
  257.          err_msg( line_nr, ERR_EOF);
  258.          /* error message */
  259.          }
  260.       }
  261.    CloseFile(infile);               // Close input file
  262.    CloseFile(outfile);              // Close output file
  263.    }
  264. /* EasyCODE ) */
  265. /* EasyCODE ) */
  266.